#pragma once

#include <QPainter>
#include <QWidget>
#include "Const.h"

// 游戏
class Game: public QObject {
    Q_OBJECT

    // 状态
    public: enum Status {
        END,    // 已结束
        PLAYING // 游戏中
    };

    signals: void UM_GAME_OVER(bool);   // 游戏结束事件

    private: QPixmap* mBitmap;      // 后台缓冲位图
    private: QPainter mDrawer;      // 绘图者
    private: QFont mFont;           // 字体
    private: QWidget* mGameBoard;   // 游戏区域
    private: int mNumbers[Const::GAME_BOARD_GRID_COUNT_V][Const::GAME_BOARD_GRID_COUNT_H];  // 数字矩阵
    private: Status mStatus;        // 状态

    public: Game(QPixmap*, QWidget*);
    private: void afterMove(bool);
    private: void createRandomNumber();
    private: void drawAllNumbers();
    private: void drawGameBoard();
    private: void drawOneNumber(int, int, int);
    private: void gameOver(bool);
    private: bool isLost();
    private: bool isWon();
    private: void moveDown();
    private: void moveLeft();
    private: void moveRight();
    private: void moveUp();
    public: void onKeyPressed(int);
    public: void start();
};
